package jsonreader;

import java.util.HashMap;

public class JSONValue
{
	private JSONType type;
	private Object value;
	
	public JSONValue(JSONType type, Object value)
	{
		this.type = type;
		this.value = value;
	}
	public JSONType getType()
	{
		return type;
	}
	
	public Double getNumber()
	{
		if(type == JSONType.NUMBER)
		{
			return (Double)value;
		}
		return null;
	}
	public JSONValue[] getArray()
	{
		if(type == JSONType.ARRAY)
		{
			return (JSONValue[])value;
		}
		return null;
	}
	public JSONKeyValuePair getKeyValuePair()
	{
		if(type == JSONType.KEYVALUE)
		{
			return (JSONKeyValuePair)value;
		}
		return null;
	}
	@SuppressWarnings("unchecked")
	public HashMap<String, JSONValue> getObject()
	{
		if(type == JSONType.OBJECT)
		{
			return (HashMap<String, JSONValue>)value;
		}
		return null;
	}
	public Boolean getBoolean()
	{
		if(type == JSONType.BOOLEAN)
		{
			return (Boolean)value;
		}
		return null;
	}
	public String getString()
	{
		if(type == JSONType.STRING)
		{
			return (String)value;
		}
		return null;
	}
}
